﻿using System.Web.Mvc;

namespace LogikBug.ModularMvc.Navigation
{
	public class Menu
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="Menu"/> 
		/// class with the default <see cref="MenuNode"/> as 'ul' and <see cref="MenuType"/> as Main.
		/// </summary>
		public Menu()
			: this(MenuNode.Ul)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Menu"/> 
		/// class with the <see cref="MenuNode"/> and <see cref="MenuType"/> as Main.
		/// </summary>
		public Menu(MenuNode menuNode)
		{
			NodeType = menuNode;
			MenuItems = new MenuItemCollection();
		}

		#endregion

		#region Properties

		/// <summary>
		/// The HTML element type.
		/// </summary>
		public MenuNode NodeType { get; private set; }

		/// <summary>
		/// The child <see cref="MenuItem"/> collection.
		/// </summary>
		public MenuItemCollection MenuItems { get; private set; }

		#endregion

		#region Methods

		public override string ToString()
		{
			return ToMvcHtmlString().ToHtmlString();
		}

		public virtual MvcHtmlString ToMvcHtmlString()
		{
			return ToMvcHtmlString(MenuType.Main);
		}

		public virtual MvcHtmlString ToMvcHtmlString(MenuType menuType)
		{
			var sb = new TagBuilder(NodeType.TagName);
			sb.AddCssClass(string.Format("{0}-modular-menu", menuType.ToString().ToLower()));
			sb.InnerHtml = MenuItems.ToMvcHtmlString(NodeType).ToHtmlString();
			return MvcHtmlString.Create(sb.ToString());
		}

		#endregion
	}
}